<?php
if (!defined("DNREAD")) exit();
global $db,$basepref,$api,$setting;
$bc = '';
$bs = array(
            'col' => array('lang'=>'all_col',
                           'form'=>'text',
                           'value'=>10,
                           'default'=>10),
           );
if (defined('SETTING')) {
    return $bs;
}
if (isset($setting['bsarray']) && is_array($setting['bsarray'])) {
    $bs = $setting['bsarray'];
}
function bdrandoms(){ return mt_rand(-5,5); }
$inq = $db->query("SELECT * FROM ".$basepref."_down_tag ORDER BY tagrating DESC LIMIT ".$bs['col'],$setting['cachetime'],'down');
$tags = array();
$ins = $key = '';
while ($item = $db->fetchrow($inq,$setting['cache'])) {
    $tags[] = array(
    'tag' => $item['tagword'],
    'rating' => $item['tagrating'],
    'tagid' => $item['tagid'],
    'cpu' => $item['tagcpu']
    );
    $key.= $item['tagword'].' ';
}
@uksort($tags,'bdrandoms');
foreach ($tags as $k) {
    if ($k['rating'] < 20) {
        $class = 'smallmin';
    } elseif ($k['rating'] >= 20 && $k['rating'] < 40) {
        $class = 'small';
    } elseif ($k['rating'] >= 40 && $k['rating'] < 60) {
        $class = 'medium';
    } elseif ($k['rating'] >= 60 && $k['rating'] < 80) {
        $class = 'high';
    } else {
        $class = 'highmax';
    }
    $tcpu = ($siteglobal['seourl'] == 1 && $k['cpu']) ? '&amp;cpu='.$k['cpu'] : '';
    $bc.= '<span class="'.$class.'"><a href="'.$setting['site_url'].'/index.php?dn=down&amp;re=tags&amp;to=tag&amp;id='.$k['tagid'].$tcpu.'" title="'.$k['tag'].'">'.$k['tag'].'</a></span> ';
}
return $api->siteuni($bc);
?>
